package com.springboot.util.mail;

import cn.hutool.core.util.IdUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.springboot.util.config.SystemProperties;
import com.springboot.util.constant.CommonContract;
import com.springboot.util.enums.SendMessageCodeEnum;
import com.springboot.util.string.MyStringUtil;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName MailUtil
 * @Description
 * @Author zyj
 * @Date 2023/5/17 17:13
 * @Version 1.0
 **/
@Component
public class MyMailUtil {

    @Resource
    private SystemProperties systemProperties;
    /**
     * 方法描述 发送注册邮件
     *
     * @param userEmail 用户邮箱
     * @param code      验证码
     * @since: 1.0
     * @return: String 发送id
     * @author: zyj
     * @date: 2023/5/17 18:12
     */
    public String sendEmailRegister(String userEmail, String code) throws Exception {

        //替换数据
        Map<String, String> replaceValue = new HashMap<>(1);
        replaceValue.put(SendMessageCodeEnum.EMAIL_CODE_REGISTER.getReplaceValue()[0], code);
        String sendContent = MyStringUtil.replaceAllStr(SendMessageCodeEnum.EMAIL_CODE_REGISTER.getTemp(), replaceValue);

        //发送邮箱
        MailUtil.send(userEmail, CommonContract.registerMailTitle, sendContent, false);
        String simpleUUID = IdUtil.simpleUUID();
        return simpleUUID;
    }


}
